package LB2;

import static java.lang.Math.pow;
import static java.lang.Math.sin;

/**
 * Created with IntelliJ IDEA.
 * User: Борис
 * Date: 14.10.13
 * Time: 19:54
 * To change this template use File | Settings | File Templates.
 */
public class SecondRang extends AbstractCalculateDiff {
    public SecondRang(double[] interval, double h){
        super(interval,h);
    }
    public double[][] firstDiff(){
        double[][] result = new double[2][size];
        for(int i = 0; i<size; i++){
            result[0][i] = interval[i];
            if (i<size-2)
                result[1][i] = (-3*sin(interval[i])+4*sin(interval[i+1]) - sin(interval[i+2]))/(2*h);
            else result[1][i] = (sin(interval[i-2])-4*sin(interval[i-1]) + 3*sin(interval[i]))/(2*h);
        }
        return result;
    }
    public double[][] secondDiff(){
        double[][] result = new double[2][size];
        for(int i = 0; i<size; i++){
            result[0][i] = interval[i];
            if (i<size-3)
                result[1][i] = (2*sin(interval[i]) - 5*sin(interval[i+1]) + 4*sin(interval[i+2]) - sin(interval[i+3]))/pow(h,2);
            else result[1][i] = (2*sin(interval[i]) - 5*sin(interval[i-1]) + 4*sin(interval[i-2]) - sin(interval[i-3]))/pow(h,2);
        }
        return result;
    }
}
